package com.yms.test;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @version : 1.0
 * @Author: yangmingsong
 * @Date: 2021/3/22-03-22-14:20
 * @Description: ting-yu-project
 */
public class CodeGenerator {
    public static void main(String[] args) {
        AutoGenerator agr = new AutoGenerator();
        //全局配置
        GlobalConfig gc = new GlobalConfig();
        String path = System.getProperty("user.dir");//动态获取当前项目的路径
        System.out.println(path);
        gc.setFileOverride(true);// 是否覆盖同名文件，默认是false
        gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(false);// XML columList
        gc.setOutputDir(path+"/TingYu/src");
        gc.setIdType(IdType.AUTO);//设置主键策略
        agr.setGlobalConfig(gc);
        //资源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/ting?useUnicode=true&useSSL=false&characterEncoding=utf8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("");
        agr.setDataSource(dsc);
        //包信息配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.yms")
                .setMapper("mapper")
                .setService("service")
                .setController("controller")
                .setEntity("pojo")
                .setXml("mapper");
        agr.setPackageInfo(pc);
        //策略配置
        /**
         * t_admin
         * t_admin_role
         * t_company
         * t_host
         * t_host_power
         * t_married_person
         * t_menu
         * t_order
         * t_planner
         * t_role
         * t_role_menu
         */
        StrategyConfig stConfig = new StrategyConfig();
        stConfig.setCapitalMode(true) //全局大写命名
                .setNaming(NamingStrategy.underline_to_camel) // 数据库表映射到实体的命名策略
                .setTablePrefix("t_")
           //     .setInclude("t_company"); // 生成的表，多个表继续传递即可，String类型的可变参数
               .setInclude("t_role_menu");
        agr.setStrategy(stConfig);
        //执行
        agr.execute();
    }
}
